﻿using System;
using System.Windows;
using System.Windows.Automation;
using System.Windows.Automation.Text;

namespace QuickUIT.Controls
{
    /// <summary>
    /// Represents a tooltip control. 
    /// </summary>
    public class UIToolTip : UIBaseControl
    {
        /// <summary>
        /// Gets the text range that encloses the main text of a document. 
        /// </summary>
        public new TextPatternRange DocumentRange
        {
            get { return base.DocumentRange; }
        }

        /// <summary>
        /// Gets a value that indicates the type of text selection that is supported by the control. 
        /// </summary>
        public new SupportedTextSelection SupportedTextSelection
        {
            get { return base.SupportedTextSelection; }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UIToolTip"/> class. 
        /// </summary>
        public UIToolTip()
            : base(ControlType.ToolTip)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UIToolTip"/> class.
        /// </summary>
        /// <param name="parent">The parent of this control.</param>
        public UIToolTip(UIBaseControl parent)
            : base(parent, ControlType.ToolTip)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UIToolTip"/> class.
        /// </summary>
        /// <param name="locator">The locator used to find the specific control.</param>
        public UIToolTip(string locator)
            : base(null, ControlType.ToolTip, locator)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UIToolTip"/> class.
        /// </summary>
        /// <param name="parent">The parent of this control.</param>
        /// <param name="locator">The locator used to find the specific control.</param>
        public UIToolTip(UIBaseControl parent, string locator)
            : base(parent, ControlType.ToolTip, locator)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UIToolTip"/> class.
        /// </summary>
        /// <param name="control">The underlying <see cref="AutomationElement"/> of the control.</param>
        public UIToolTip(AutomationElement control) : base(control, ControlType.ToolTip)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="UIToolTip"/> class.
        /// </summary>
        /// <param name="parent">The parent of the control</param>
        /// <param name="control">The underlying <see cref="AutomationElement"/> of the control.</param>
        public UIToolTip(UIBaseControl parent, AutomationElement control) : base(parent, control, ControlType.ToolTip)
        {
        }

        /// <summary>
        /// Retrieves a collection of text ranges that represents the currently selected text in a text-based control
        /// </summary>
        /// <returns>A collection of disjoint text ranges.</returns>
        /// <exception cref="InvalidOperationException">The control pattern cannot be performed by the element.</exception>
        /// <exception cref="ElementNotAvailableException">The current element does not exist anymore.</exception>
        public new TextPatternRange[] GetTextSelection()
        {
            return base.GetTextSelection();
        }

        /// <summary>
        /// Retrieves an array of disjoint text ranges from a text-based control where each text range represents a contiguous span of visible text.
        /// </summary>
        /// <returns>The collection of visible text ranges within the container or an empty array.</returns>
        /// <exception cref="InvalidOperationException">The control pattern cannot be performed by the element.</exception>
        /// <exception cref="ElementNotAvailableException">The current element does not exist anymore.</exception>
        public new TextPatternRange[] GetVisibleRanges()
        {
            return base.GetVisibleRanges();
        }

        /// <summary>
        /// Retrieves a text range enclosing a child element such as an image, hyperlink, Microsoft Excel spreadsheet, or other embedded object. 
        /// </summary>
        /// <returns>A range that spans the child element.</returns>
        /// <exception cref="ArgumentNullException">The child element is null.</exception>
        /// <exception cref="InvalidOperationException">The control pattern cannot be performed by the element.</exception>
        /// <exception cref="ElementNotAvailableException">The current element does not exist anymore.</exception>
        public new TextPatternRange RangeFromChild(AutomationElement childElement)
        {
            return base.RangeFromChild(childElement);
        }

        /// <summary>
        /// Returns the degenerate (empty) text range nearest to the specified screen coordinates. 
        /// </summary>
        /// <param name="screenLocation">The location in screen coordinates.</param>
        /// <returns>A degenerate range nearest the specified location. Null is never returned.</returns>
        /// <exception cref="ArgumentException">A given point is outside the <see cref="AutomationElement"/> associated with the text pattern.</exception>
        /// <exception cref="InvalidOperationException">The control pattern cannot be performed by the element.</exception>
        /// <exception cref="ElementNotAvailableException">The current element does not exist anymore.</exception>
        public new TextPatternRange RangeFromPoint(Point screenLocation)
        {
            return base.RangeFromPoint(screenLocation);
        }

        /// <summary>
        /// Closes a the tooltip. 
        /// </summary>
        /// <exception cref="InvalidOperationException">The control pattern cannot be performed by the element.</exception>
        /// <exception cref="ElementNotAvailableException">The element is not available anymore.</exception>
        public new void Close()
        {
            base.Close();
        }
    }
}
